Griffin Shelor
17-4-2024

In-class Exercise: Folium Maps¶

In [ ]:
import pandas as pd
import numpy as np
import folium
from folium.plugins import MarkerCluster, HeatMap

Load some datasets¶

In [ ]:
# meteorites: # meteorites: https://www.kaggle.com/nasa/meteorite-landings
df_me=pd.read_csv('lecture22_meteorites.csv')
df_me
Out[ ]:
name id nametype recclass mass fall year reclat reclong GeoLocation
0 Aachen 1 Valid L5 21.0 Fell 1880.0 50.77500 6.08333 (50.775000, 6.083330)
1 Aarhus 2 Valid H6 720.0 Fell 1951.0 56.18333 10.23333 (56.183330, 10.233330)
2 Abee 6 Valid EH4 107000.0 Fell 1952.0 54.21667 -113.00000 (54.216670, -113.000000)
3 Acapulco 10 Valid Acapulcoite 1914.0 Fell 1976.0 16.88333 -99.90000 (16.883330, -99.900000)
4 Achiras 370 Valid L6 780.0 Fell 1902.0 -33.16667 -64.95000 (-33.166670, -64.950000)
... ... ... ... ... ... ... ... ... ... ...
45711 Zillah 002 31356 Valid Eucrite 172.0 Found 1990.0 29.03700 17.01850 (29.037000, 17.018500)
45712 Zinder 30409 Valid Pallasite, ungrouped 46.0 Found 1999.0 13.78333 8.96667 (13.783330, 8.966670)
45713 Zlin 30410 Valid H4 3.3 Found 1939.0 49.25000 17.66667 (49.250000, 17.666670)
45714 Zubkovsky 31357 Valid L6 2167.0 Found 2003.0 49.78917 41.50460 (49.789170, 41.504600)
45715 Zulu Queen 30414 Valid L3.7 200.0 Found 1976.0 33.98333 -115.68333 (33.983330, -115.683330)

45716 rows × 10 columns

In [ ]:
# global volcanos
df_volc = pd.read_csv("lecture20_volc.csv")
df_volc
Out[ ]:
Number Name Country Region Type Activity Evidence Last Known Eruption Latitude Longitude Elevation (Meters) Dominant Rock Type Tectonic Setting
0 210010 West Eifel Volcanic Field Germany Mediterranean and Western Asia Maar(s) Eruption Dated 8300 BCE 50.170 6.850 600 Foidite Rift Zone / Continental Crust (>25 km)
1 210020 Chaine des Puys France Mediterranean and Western Asia Lava dome(s) Eruption Dated 4040 BCE 45.775 2.970 1464 Basalt / Picro-Basalt Rift Zone / Continental Crust (>25 km)
2 210030 Olot Volcanic Field Spain Mediterranean and Western Asia Pyroclastic cone(s) Evidence Credible Unknown 42.170 2.530 893 Trachybasalt / Tephrite Basanite Intraplate / Continental Crust (>25 km)
3 210040 Calatrava Volcanic Field Spain Mediterranean and Western Asia Pyroclastic cone(s) Eruption Dated 3600 BCE 38.870 -4.020 1117 Basalt / Picro-Basalt Intraplate / Continental Crust (>25 km)
4 211001 Larderello Italy Mediterranean and Western Asia Explosion crater(s) Eruption Observed 1282 CE 43.250 10.870 500 No Data Subduction Zone / Continental Crust (>25 km)
... ... ... ... ... ... ... ... ... ... ... ... ...
1503 390130 Zavodovski United Kingdom Antarctica Stratovolcano Eruption Observed 2016 CE -56.300 -27.570 551 Basalt / Picro-Basalt Subduction Zone / Oceanic Crust (< 15 km)
1504 390140 Protector Seamounts United Kingdom Antarctica Submarine Eruption Observed 1962 CE -55.912 -28.167 -55 Rhyolite Subduction Zone / Oceanic Crust (< 15 km)
1505 390812 Rittmann, Mount Antarctica Antarctica Shield Unrest / Pleistocene Unknown -73.450 165.500 2600 NaN Intraplate / Continental Crust (>25 km)
1506 390829 James Ross Island Antarctica Antarctica Shield Evidence Credible Unknown -64.150 -57.750 1630 Basalt / Picro-Basalt Intraplate / Continental Crust (>25 km)
1507 390847 Melville Antarctica Antarctica Stratovolcano Evidence Uncertain Unknown -62.020 -57.670 549 NaN Intraplate / Continental Crust (>25 km)

1508 rows × 12 columns

In [ ]:
# global earthquakes
df_eq = pd.read_csv("lecture20_eq.csv")
df_eq
Out[ ]:
Date Time Latitude Longitude Type Depth Depth Error Depth Seismic Stations Magnitude Magnitude Type ... Magnitude Seismic Stations Azimuthal Gap Horizontal Distance Horizontal Error Root Mean Square ID Source Location Source Magnitude Source Status
0 01/02/1965 13:44:18 19.2460 145.6160 Earthquake 131.60 NaN NaN 6.0 MW ... NaN NaN NaN NaN NaN ISCGEM860706 ISCGEM ISCGEM ISCGEM Automatic
1 01/04/1965 11:29:49 1.8630 127.3520 Earthquake 80.00 NaN NaN 5.8 MW ... NaN NaN NaN NaN NaN ISCGEM860737 ISCGEM ISCGEM ISCGEM Automatic
2 01/05/1965 18:05:58 -20.5790 -173.9720 Earthquake 20.00 NaN NaN 6.2 MW ... NaN NaN NaN NaN NaN ISCGEM860762 ISCGEM ISCGEM ISCGEM Automatic
3 01/08/1965 18:49:43 -59.0760 -23.5570 Earthquake 15.00 NaN NaN 5.8 MW ... NaN NaN NaN NaN NaN ISCGEM860856 ISCGEM ISCGEM ISCGEM Automatic
4 01/09/1965 13:32:50 11.9380 126.4270 Earthquake 15.00 NaN NaN 5.8 MW ... NaN NaN NaN NaN NaN ISCGEM860890 ISCGEM ISCGEM ISCGEM Automatic
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
23407 12/28/2016 08:22:12 38.3917 -118.8941 Earthquake 12.30 1.2 40.0 5.6 ML ... 18.0 42.47 0.120 NaN 0.1898 NN00570710 NN NN NN Reviewed
23408 12/28/2016 09:13:47 38.3777 -118.8957 Earthquake 8.80 2.0 33.0 5.5 ML ... 18.0 48.58 0.129 NaN 0.2187 NN00570744 NN NN NN Reviewed
23409 12/28/2016 12:38:51 36.9179 140.4262 Earthquake 10.00 1.8 NaN 5.9 MWW ... NaN 91.00 0.992 4.8 1.5200 US10007NAF US US US Reviewed
23410 12/29/2016 22:30:19 -9.0283 118.6639 Earthquake 79.00 1.8 NaN 6.3 MWW ... NaN 26.00 3.553 6.0 1.4300 US10007NL0 US US US Reviewed
23411 12/30/2016 20:08:28 37.3973 141.4103 Earthquake 11.94 2.2 NaN 5.5 MB ... 428.0 97.00 0.681 4.5 0.9100 US10007NTD US US US Reviewed

23412 rows × 21 columns

Q1. Extract the latitude and longitude values from the meteorites dataframe, removing NaN values¶

In [ ]:
## dropping NA
clean_meteorites = df_me.dropna()

## extracting lat and lon
clean_me_lat = clean_meteorites['reclat']
clean_me_lon = clean_meteorites['reclong']

Q2. Use folium to plot the Q1 (lat,lon) values with circle markers and the color of your choice.¶

This a global map, so choose and appropriate location and zoom_start.

In [ ]:
# choose coordinates for center
clat = clean_me_lat.mean()
clon = clean_me_lon.mean()

# create map
m = folium.Map(location=[clat, clon], zoom_start=1)

# add markers for q1 dataframe
for lat,lon in zip(clean_me_lat, clean_me_lon):
    marker = folium.CircleMarker([lat, lon], radius=1, color='red')
    marker.add_to(m)
    
# display
display(m)
Make this Notebook Trusted to load map: File -> Trust Notebook

Q3. Now make a folium heatmap of the meteorite lat/lon values¶

In [ ]:
# Create data for heatmap
heat_data = [[lati, loni] for lati, loni in zip(clean_me_lat, clean_me_lon)]

# Create Map
m = folium.Map(location=[0.0, 0.0], zoom_start=1)

# Plot the heatmap 
HeatMap(heat_data).add_to(m)

# Show Results
display(m)
Make this Notebook Trusted to load map: File -> Trust Notebook

Q4. Switching datasets now... Extract the latitude and longitude values for both volcanoes and earthquakes between latitudes 45 to 53 and longitudes -125 to -120.¶

In [ ]:
## extracting lat/long from earthquakes
df_eq_subset = df_eq[(df_eq['Latitude']>=45) & (df_eq['Latitude']<=53) & (df_eq['Longitude'] >= -125) & (df_eq['Longitude'] <= -120)]

## extracting lat/long from volcanoes
df_volc_subset = df_volc[(df_volc['Latitude']>=45) & (df_volc['Latitude']<=53) & (df_volc['Longitude'] >= -125) & (df_volc['Longitude'] <= -120)]

Q5. Use folium to plot the volcano (lat,lon) values with red triangles and earthquake (lat,lon) values with blue circles. Select an appropriate map location near the center of the study region, and use a zoom_start=5.5.¶

In [ ]:
# create map
m = folium.Map(location=[50, -122.5], zoom_start=5.5)

# add markers for earthquakes and volcanoes
for lat,lon in zip(df_eq_subset['Latitude'], df_eq_subset['Longitude']):
    eq_marker = folium.CircleMarker([lat, lon], radius=3, fill = True, color='blue')
    eq_marker.add_to(m)
for lat,lon in zip(df_volc_subset['Latitude'], df_volc_subset['Longitude']):
    volc_marker = folium.RegularPolygonMarker([lat, lon], radius=3, fill = True, color='red', number_of_sides = 3)
    volc_marker.add_to(m)
    
# display
display(m)
Make this Notebook Trusted to load map: File -> Trust Notebook

Save your notebook and output an html version. To receive credit for this in-class exercise upload both the .html and .ipynb file.¶